﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Models;

namespace TeacherMS.Windows
{
    public partial class EditClassForm : Form
    {
        public EditClassForm(Class @class)
        {
            InitializeComponent();
            this.@class = @class;
        }
         private Class @class=null;
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                @class.Name = textBoxName.Text.Trim();
                @class.Grade = comboBoxGrade.Text.Trim();
                @class.ClassNumber = comboBoxClass.Text.Trim();
                @class.InsertDate = DateTime.Now;
                if (string.IsNullOrEmpty(@class.Name))
                {
                    MessageBox.Show("名字不为空");
                }
                var count = new ClassService().Update(@class);
                if (count > 0)
                {
                    MessageBox.Show("修改成功");
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            catch
            {
                MessageBox.Show("修改失败");
            }
            //@class.Name = textBoxName.Text.Trim();
            //@class.Grade = comboBoxGrade.Text.Trim();
            //@class.ClassNumber = comboBoxClass.Text.Trim();
            //@class.InsertDate = DateTime.Now;
            //if (string.IsNullOrEmpty(@class.Name)) {
            //    MessageBox.Show("名字不为空");
            //}
            //var count=new ClassService().Update(@class);
            //if (count > 0)
            //{
            //    MessageBox.Show("修改成功");
            //}
            //else
            //{
            //    MessageBox.Show("修改失败");
            //}
            DialogResult  = DialogResult.OK;
            Close();
        }

        private void comboBoxClass_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label10_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxGrade_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBoxName_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void EditClassForm_Load(object sender, EventArgs e)
        {
            textBoxName.Text = @class.Name;
            comboBoxGrade.Text = @class.Grade;
            comboBoxClass.Text = @class.ClassNumber;
        }
    }
}
